package com.zhanghe.study.design_pattern.singleton_pattern.lazy;

/**
 * 懒汉模式
 * @Author: zhanghe
 * @Date: 2020/4/21 17:42
 */
public class Singleton {
    private static Singleton instance = null;

    private Singleton(){

    }

    public static Singleton newInstance(){
        // 在需要的时候进行创建，如果已存在，直接返回之前的对象
        if(instance == null){
            instance = new Singleton();
            System.out.println("创建单例实例");
        }
        return instance;
    }
}
